<?php
/**
 * 
 * modelo de SCT_From
 * @author Natanael Acosta
 * 
 */
class Mfrom extends Model{

	  private $_nameTable = "SCT_From";
	  
	  public function __construct()
	  {
	     parent::Model();
	     $this->load->database();
	  }
	  
      public function loadFrom($start = false, $offset = false, $sortname = false, $sortorder = false)
      {
            
           if($offset != false)
		       $this->db->limit($offset, $start);

		   if($sortname != false && $sortorder != false) 
			    $this->db->order_by($sortname, $sortorder);
				  
		    $result = $this->db->get_where($this->_nameTable);
	
			return $this->GetArrayFromQueryResult($result);
			
       }
       
       public function loadRegistroByWhere($where)
       {
            $result = $this->db->get_where($this->_nameTable, $where);
            return $this->GetArrayFromQueryResult($result);
       }
       
       public function LoadRegistroById($id) 
	   {
		   $qresult = $this->db->get_where($this->_nameTable, array('idFrom' => $id));		
		
		   if ($qresult->num_rows() == 0)
		   {
			 return false;
		   }	
           
		   return new SCT_From($qresult->row());
	    }
       
       private function GetArrayFromQueryResult($result)
       {
           if ($result->num_rows() == 0)
				      return false;
	
			 $data_arr = array();
	
			foreach ($result->result() as $record) {
				$data_arr[] = new SCT_From($record);
		    }
	
			return $data_arr;
       }
       
       public function addRegistro($data)
       {
          if ($this->db->insert($this->_nameTable,$data)) 
             return true;
             
            return false;   
         
       }
       
       public function updateRegistro($data, $where)
       {
          if ($this->db->update($this->_nameTable,$data, $where))
             return true;

             return false; 
      
       }
       
       public function daleteRegistro($where)
       {
           if($this->db->delete($this->_nameTable, $where))
              return true;
              
             return false;      
       }


}

class SCT_From{

      private $_idFrom = 0;
      private $_title = "";
      private $_body = "";

      public function __construct($ojt)
      {
          $this->setIdFrom($ojt->idFrom);
          $this->setTitle($ojt->title);
          $this->setBody($ojt->body);
      }
      
      public function getIdFrom()
      {
         return $this->_idFrom;
      }
      
      public function setIdFrom($id)
      {
          $this->_idFrom = $id;
      }
      
      public function getTitle()
      {
         return $this->_title;
      }
      
      public function setTitle($id)
      {
          $this->_title = $id;
      }
      
      public function getBody()
      {
         return $this->_body;
      }
      
      public function setBody($id)
      {
          $this->_body = $id;
      }
      
      
}